package ess.hardware;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;

import ess.control.ElevatorManager;


public class ElevatorSimulationFrame extends JFrame{
	
	/**
	 * 
	 */
	
	private static final long serialVersionUID = 5638994316866126109L;
	
	public static void main(String[] args) {

		// Create a frame and display it
		ElevatorSimulationFrame frame = new ElevatorSimulationFrame();
		
        frame.setBounds(100,50,160*3+40,800);
        
        //frame.setLocationRelativeTo(null);
        frame.setTitle("Elevator Simulator");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        frame.setVisible(true);
        frame.repaint();
    }
	
	public ElevatorSimulationFrame()
	{
		super();
		//JPanel mainPanel = new JPanel(new BorderLayout());
		
		JPanel elevatorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		//mainPanel.setSize(1000, 700);
		
		
		//ButtonPanel.setBackground(Color.darkGray);
		//ButtonPanel.setLayout(new BoxLayout(ButtonPanel,BoxLayout.Y_AXIS));
		int elevatorWidth = 160;
		int elevatorHeight = 160;
		int numOfFloors = 7;
		int baseFloor = 1;
		
		
		Elevator e1 = new Elevator(1, numOfFloors, baseFloor, elevatorWidth, elevatorWidth*numOfFloors/2);
		ElevatorManager.getInstance().registerElevator(e1);
		elevatorPanel.add(e1);
		
		Elevator e2 = new Elevator(2, numOfFloors, baseFloor, elevatorWidth, elevatorWidth*numOfFloors/2);
		ElevatorManager.getInstance().registerElevator(e2);
		elevatorPanel.add(e2);
		
		e1.addDoorClosingSensorEventListener(ElevatorManager.getInstance().getElevatorProxy(e1.getId()));
		e2.addDoorClosingSensorEventListener(ElevatorManager.getInstance().getElevatorProxy(e2.getId()));
		
		JPanel elevatorOperationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		ElevatorOperationPanel eop1 = new ElevatorOperationPanel(e1, elevatorWidth, elevatorHeight);
		ElevatorOperationPanel eop2 = new ElevatorOperationPanel(e2, elevatorWidth, elevatorHeight);
		
		ElevatorManager.getInstance().getElevatorProxy(e1.getId()).registerElevatorOperationPanel(eop1);
		ElevatorManager.getInstance().getElevatorProxy(e2.getId()).registerElevatorOperationPanel(eop2);
		
		eop1.addElevatorOperationEventListener(ElevatorManager.getInstance().getElevatorProxy(e1.getId()));
		eop2.addElevatorOperationEventListener(ElevatorManager.getInstance().getElevatorProxy(e2.getId()));
		
		elevatorOperationPanel.add(eop1);
		elevatorOperationPanel.add(eop2);
		
		FileOperationPanel filePanel = new FileOperationPanel();
		elevatorOperationPanel.add(filePanel);
		
		JPanel floorButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		FloorButtonPanel fbp = new FloorButtonPanel(7, 160, elevatorWidth*numOfFloors/2);
		fbp.addFloorOperationEventListener(ElevatorManager.getInstance());
		ElevatorManager.getInstance().registerFloorButtonPanel(fbp);
		floorButtonPanel.add(fbp);

		getContentPane().add(BorderLayout.CENTER,elevatorPanel);
		getContentPane().add(BorderLayout.SOUTH,elevatorOperationPanel);
		getContentPane().add(BorderLayout.EAST,floorButtonPanel);
		
	}
	
}
